package com.zjj.day0425.big;

/**
 * @author zhoujunjie
 * @desc TODO
 * @date 2025/4/25
 */
import java.util.Scanner;

public class BigIntegerWork {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个十六进制的数值字符串:");
        String input = scanner.nextLine();

        long decimal = 0;
        int power = 0;
        for (int i = input.length() - 1; i >= 0; i--) {
            char c = input.charAt(i);
            int digitValue;
            if (c >= '0' && c <= '9') {
                digitValue = c - '0';
            } else if (c >= 'A' && c <= 'F') {
                digitValue = c - 'A' + 10;
            } else if (c >= 'a' && c <= 'f') {
                digitValue = c - 'a' + 10;
            } else {
                System.out.println("输入的不是有效的十六进制字符串。");
                return;
            }
            decimal += digitValue * Math.pow(16, power);
            power++;
        }
        System.out.println("对应的十进制数值为: " + decimal);
    }
}